//
//  NovelHeaderView.m
//  ChineseCollegeStudentsNetwork
//
//  Created by 魏苏扬 on 2018/8/9.
//  Copyright © 2018年 刘喆. All rights reserved.
//

#import "NovelHeaderView.h"
@interface NovelHeaderView()
@property (nonatomic, strong) UIImageView *coverImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *freeLabel;
@property (nonatomic, strong) UILabel *payLabel;
@property (nonatomic, strong) UILabel *paperPriceLabel;
@property (nonatomic, strong) UILabel *elePriceLabel;
@property (nonatomic, strong) UIButton *nextButton;
@property (nonatomic, strong) UIButton *readBtn;

@end
@implementation NovelHeaderView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
        [self setupLayout];
    }
    return self;
}
#pragma mark- UI
- (void)setupUI{
    
    self.coverImageView = [[UIImageView alloc] init];
    self.coverImageView.backgroundColor = UIColorFromRGBHex(0x896fb8);
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.textColor = UIColorFromRGBHex(0x666666);
    self.timeLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    
    self.freeLabel = [[UILabel alloc] init];
    self.freeLabel.textColor = UIColorFromRGBHex(0x666666);
    self.freeLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    
    self.payLabel = [[UILabel alloc] init];
    self.payLabel.textColor = UIColorFromRGBHex(0x666666);
    self.payLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    
    self.paperPriceLabel = [[UILabel alloc] init];
    self.paperPriceLabel.textColor = UIColorFromRGBHex(0x666666);
    self.paperPriceLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    
    self.elePriceLabel = [[UILabel alloc] init];
    self.elePriceLabel.textColor = UIColorFromRGBHex(0x666666);
    self.elePriceLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    
    
    self.readBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.readBtn.backgroundColor = kColorTint;
    self.readBtn.titleLabel.textColor = [UIColor whiteColor];
    self.readBtn.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    self.readBtn.layer.cornerRadius = 5;
    self.readBtn.layer.masksToBounds = YES;
    [self.readBtn setTitle:@"付费阅读" forState:UIControlStateNormal];
    [self.readBtn addTarget:self action:@selector(readBtnAction) forControlEvents:UIControlEventTouchUpInside];
    

    self.nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextButton.backgroundColor = kColorTint;
    self.nextButton.titleLabel.textColor = [UIColor whiteColor];
    self.nextButton.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    self.nextButton.layer.cornerRadius = 5;
    self.nextButton.layer.masksToBounds = YES;
    [self.nextButton setTitle:@"纸质杂志购买" forState:UIControlStateNormal];
    [self.nextButton addTarget:self action:@selector(nextButtonAction) forControlEvents:UIControlEventTouchUpInside];

}

- (void)setupLayout{
    [self addSubview:self.coverImageView];
    [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(10).priorityHigh();
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(120);
    }];
    [self addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.coverImageView.mas_right).offset(10);
        make.top.mas_equalTo(self.coverImageView);
        make.right.mas_equalTo(-10);
    }];
    
    [self addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
    }];
    
    [self addSubview:self.freeLabel];
    [self.freeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(5);
    }];
    
    [self addSubview:self.payLabel];
    [self.payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.freeLabel.mas_bottom).offset(5);
    }];
    
    [self addSubview:self.paperPriceLabel];
    [self.paperPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.payLabel.mas_bottom).offset(5);
    }];
    
    [self addSubview:self.elePriceLabel];
    [self.elePriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.paperPriceLabel.mas_bottom).offset(5);
    }];
    
    
    [self addSubview:self.readBtn];
    [self.readBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.elePriceLabel.mas_bottom).offset(8);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(25);
    }];
    
    [self addSubview:self.nextButton];
    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.equalTo(self.readBtn);
        make.width.mas_equalTo(105);
        make.top.mas_equalTo(self.readBtn.mas_bottom).offset(8);
    }];
}

- (void)setObj:(CommonModel *)obj {

    
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:obj.imageUrl] placeholderImage:[UIImage imageNamed:@"飞艇"]];

    self.titleLabel.text = obj.title;
    self.timeLabel.text = [NSString stringWithFormat:@"上架时间：%@",obj.addDate];
    self.freeLabel.text = [NSString stringWithFormat:@"免费阅读篇数：%@篇",obj.freeCount];
    self.payLabel.text = [NSString stringWithFormat:@"付费阅读篇数：%@篇",obj.payCount];
    self.paperPriceLabel.text = [NSString stringWithFormat:@"纸质购买价格：%@元",obj.paperCost];
    self.elePriceLabel.text = [NSString stringWithFormat:@"全刊电子阅读价格：%@元",obj.readingCost];
}

- (void)nextButtonAction {
    _buyClickBlock(1);
}

- (void)readBtnAction {
    _buyClickBlock(2);
}



@end
